<?php
namespace app\index\controller;

use app\common\controller\Common;
use org\Page;
use think\Exception;
use think\facade\Cache;
use think\facade\Config;
use think\facade\Request;

class Tags extends Common
{

    protected function initialize()
    {
        parent::initialize();

    }

    /**
     * 专辑详情
     * @param int $id 专辑id
     * @return mixed
     * @throws Exception
     */
    public function detail($id = 0) {

        $page = 1;
        $page_size = 18; //页码大小
        $where = explode("_",$id);
        if (count($where) > 1) {
            $page = $where[1];
        }
        $id = $where[0];

        $detail = curl_server(sprintf("apiv2/specialdetail?id=%d&page=%d&page_size=%d",$id,$page,$page_size));
        $detail = $detail['data'];
        $detail['tags'] = explode(",",$detail['tags']);

        //分页
        $pages = new Page(sprintf("tags/%d_{PAGE}",$id),$page,$detail['total'],$page_size);
        if (isMobileDomain()) {
            $pages->setConfig("theme",'%NO_PREV% %UP_PAGE% %DOWN_PAGE%');
            $show = $pages->showHs13Mobile();
        }else {
            $show = $pages->show();
        }

        $this->assign("pages",$show);

        $this->site_seo('special_detail',array('title' => $detail['title'],'introduction' => $detail['introduction']));
        return $this->fetch('detail',['detail' => $detail]);
    }

    /**
     * 专辑列表
     * @param int $page 页码
     * @return mixed
     * @throws Exception
     */
    public function index($page = 1)
    {
        $page_size = 16; //页码大小
        $data = curl_server(sprintf("apiv2/speciallist?page=%d&page_size=%d",$page,$page_size));
        $data = $data['data'];

        //分页
        $pages = new Page("tags/list_{PAGE}",$page,$data['total'],$page_size);
        if (isMobileDomain()) {
            $pages->setConfig("theme",'%NO_PREV% %UP_PAGE% %DOWN_PAGE%');
            $show = $pages->showHs13Mobile();
        }else {
            $show = $pages->show();
        }

        $this->assign("pages",$show);

        $this->site_seo('special_list');
        return $this->fetch('index',['total' => $data['total'],'list' => $data['list']]);
    }
}

